package com.meida.module.bus.provider.handler;

import com.meida.common.base.entity.EntityMap;
import com.meida.common.mybatis.interceptor.PageInterceptor;
import com.meida.common.mybatis.model.PageParams;
import com.meida.common.mybatis.query.CriteriaQuery;
import com.meida.module.bus.client.entity.BusOrder;
import com.meida.module.marketing.client.entity.MkgCoupon;
import com.meida.module.marketing.client.entity.MkgCouponUser;
import com.meida.module.user.client.entity.AppUser;
import org.springframework.stereotype.Component;

/**
 * 用户优惠券列表
 */
@Component
public class MkgCouponUserPageListHandler implements PageInterceptor<MkgCouponUser> {

    @Override
    public void prepare(CriteriaQuery<MkgCouponUser> cq, PageParams pageParams, EntityMap params) {
        cq.clear();
        String beginDate = params.get("beginDate");
        String endDate = params.get("endDate");
        cq.select(MkgCouponUser.class, "couponUserId", "couponId", "userId", "shopId", "useState", "useTime", "orderId", "userExpireBeginDate", "userExpireEndDate", "createTime");
        cq.select(MkgCoupon.class, "couponTitle", "couponType", "productId", "withAmount", "couponAmount");
        cq.select(AppUser.class, "userName", "nickName", "userNo", "mobile");
        cq.select(BusOrder.class, "orderNo");
        cq.like(BusOrder.class, "orderNo");
        cq.like(AppUser.class, "userName");
        cq.like(AppUser.class, "mobile");
        cq.eq(MkgCouponUser.class, "useState");
        cq.createJoin(AppUser.class).setMainField("userId").setJoinField("userId");
        cq.createJoin(BusOrder.class).setMainField("orderId").setJoinField("orderId");
        cq.ge("DATE_FORMAT(couponuser.createTime,'%Y-%m-%d')", beginDate);
        cq.le("DATE_FORMAT(couponuser.createTime,'%Y-%m-%d')", endDate);
    }
}
